<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s"  uri="/struts-tags" %>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix='fmt' uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
   	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <link href="<%=request.getContextPath()%>/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="<%=request.getContextPath()%>/js/jquery-2.0.3.min.js" type="text/javascript"></script>
    <script src="<%=request.getContextPath()%>/js/bootstrap.js" type="text/javascript"></script>  
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrapValidator.css"/>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrapValidator.js"></script>
    <script src="<%=request.getContextPath()%>/js/jquery.twbsPagination.js" type="text/javascript"></script>   
    <script type="text/javascript">
    $(document).ready(function () {
	    $('#pagination-demo').twbsPagination({	    	
	        totalPages: ${pageCount},
	        visiblePages: ${pageCount}>10?10:${pageCount},
			startPage:${page},
	        version: '1.1',
	        first: "首页",
	        last: "未页",
	        prev: '上一页',
	        next: '下一页',
	        onPageClick: function (event, page) {	        	
	        	if(page!=${page}){
	        		var params="${params}";
	        		if(params!='choose'){
						document.getElementById("defaultForm").action="<%=request.getContextPath()%>/productAttrDict/ProductAttrDict_listByPage.action?page="+ page +"&rows=10";
	        		}
	        		if(params=='choose'){
   					    document.getElementById("defaultForm").action="<%=request.getContextPath()%>/productAttrDict/ProductAttrDict_listByPage.action?params=choose&page="+ page +"&rows=10";
	        		}
        		    document.getElementById("defaultForm").submit();
	        	}	        	
	        }
	    });

    }); 
    
    //准备数据并显示修改数据字典的模态框
    function showUpdateAttrDict(dictId,attrId,originalValue,standardValue,shortValue,creator,creationTime){
    	$("#myModalLabel").html("修改属性值数据字典");
    	//将数据放入模态框
    	$("#dictId").val(dictId);
    	$("#originalValue").val(originalValue);
    	$("#standardValue").val(standardValue);
    	$("#shortValue").val(shortValue);
    	$("#creator").val(creator);
    	$("#creationTime").val(creationTime);
    	$("#saveBtn").attr("onclick","updateAttrDict()");
    	//显示模态框
    	$('#myModal').modal({keyboard: true});
    	
    }
    
    function updateAttrDict(){
    	var data = $("#attrDicMng").serialize();
    	data = decodeURIComponent(data,true);
    	$.ajax({
    		url:"<%=request.getContextPath()%>/productAttrDict/ProductAttrDict_updateAttrDict.action?"+data+"&t1.productAttr.id=${t1.productAttr.id}",
    		dataType:"json",
    		success:function(value){
    			alert(value.message);
    			if(value.success==true){
	   				//隐藏模态框
	   				$('#myModal').modal('hide');
    			}
    			
    		}
    		
    	});
    }
    
    //显示添加数据字典模态框
    function showAddAttrDict(){
    	$("#myModalLabel").html("添加属性值数据字典");
    	//先清空模态框中的数据
    	$("#dictId").val("");
    	$("#originalValue").val("");
    	$("#standardValue").val("");
    	$("#shortValue").val("");
    	$("#creator").val("");
    	$("#creationTime").val("");
    	$("#saveBtn").attr("onclick","addAttrDict()");
    	
    	//显示模态框
    	$('#myModal').modal({keyboard: true});
    	
    }
    
    function addAttrDict(){
    	var data = $("#attrDicMng").serialize();
    	data = decodeURIComponent(data,true);
    	$.ajax({
    		url:"<%=request.getContextPath()%>/productAttrDict/ProductAttrDict_addAttrDict.action?"+data+"&t1.productAttr.id=${t1.productAttr.id}",
    		dataType:"json",
    		success:function(value){
    			alert(value.message);
    			if(value.success==true){
    				//隐藏模态框
    				$('#myModal').modal('hide');
    			}
    			
    		}
    		
    	});
    }
    
    function dele(id)
    {
    	var r=confirm("是否删除？");
    	if(r)
   		{	
    		location.href="<%=request.getContextPath()%>/productAttrDict/ProductAttrDict_delete.action?page="+${page}+"&id="+id+"&t1.productAttr.id=${t1.productAttr.id}";
   		}
    	
    }
    </script>
</head>

<body>
<c:if test="${params!='choose' }">
<div class="panel" style="height: 80%">
	<div class="panel panel-primary">
	    <div class="panel-heading">属性值数据字典</div>
	    <div class="panel-body"> 
	
			<form class="form-horizontal" id="defaultForm" action="ProductAttrDict_listByPage?t1.productAttr.id=${t1.productAttr.id}" method="post">
			  	<table>
			  		<tr>
			  			<td><input type="text" name="t1.originalValue" class="form-control" id="value" placeholder="请输入原始值" style="width: 150px"  value="${t1.originalValue}"></td>
			  			<td><input type="text" name="t1.standardValue" class="form-control" id="value" placeholder="请输入标准值" style="width: 150px"  value="${t1.standardValue}"></td>
			  			<td><input type="text" name="t1.shortValue" class="form-control" id="value" placeholder="请输入简称" style="width: 150px"  value="${t1.shortValue}"></td>
			  			<td><button type="submit" class="btn btn-default">查询</button></td>
			  			<td><button type="button" onclick="showAddAttrDict()" class="btn btn-default">增加</button></td>
			  		</tr>
			  	</table>
			</form>
	 
	    </div>
	  
	  
	        <table class="table table-bordered table-hover">
	            <thead>
				    <tr>
						 <th>原始值</th>
						 <th>标准值</th>
						 <th>简称</th>
				         <th>操作</th>
				    </tr>
			    </thead>
			    <s:iterator value="#list">
				    <tr>
						 <th>${originalValue }</th>
						 <th>${standardValue }</th>
						 <th>${shortValue }</th>
				        <th>
					        <a class="btn btn-primary btn-sm" onclick=
					        "showUpdateAttrDict('${id }','${productAttr.id }','${originalValue }','${standardValue }','${shortValue }','${creator }','${creationTime }')" role="button" >修改</a>
				            <a class="btn btn-primary btn-sm" onclick="dele(${id })" href="#" role="button" >删除</a>
				        </th>
				    </tr>        
			    </s:iterator>
			</table> 
		<!-- 模态框（Modal） -->
		<div class="modal fade" style="overflow:hidden" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		            <div class="modal-header">
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
		                <h4 class="modal-title" id="myModalLabel"></h4>
		            </div>
		            <div class="modal-body" style="text-align: center">
		            	<form id="attrDicMng" action="">
		            		<input type="hidden" name="t.id" id="dictId">
		            		<input type="hidden" name="t.productAttr.id" value="${t1.productAttr.id}" id="attrid">
		            		<input type="hidden" name="t.creator" id="creator">
		            		<input type="hidden" name="t.creationTime" id="creationTime">
				            <div style="padding: 10px 100px 10px;">
				             	<div class="input-group" style="width: 300px">
				             		<span class="input-group-addon">原始值</span>
			            			<input type="text"  id="originalValue" name="t.originalValue" class="form-control">
			            		</div>
			            	</div>
				            <div style="padding: 10px 100px 10px;">
				             	<div class="input-group" style="width: 300px">
				             		<span class="input-group-addon">标准值</span>
			            			<input type="text"  id="standardValue" name="t.standardValue" class="form-control">
			            		</div>
			            	</div>
				            <div style="padding: 10px 100px 10px;">
				             	<div class="input-group" style="width: 300px">
				             		<span class="input-group-addon">简&nbsp;&nbsp;&nbsp;称</span>
			            			<input type="text" id="shortValue" name="t.shortValue" class="form-control">
			            		</div>
			            	</div>
			            </form>
		            </div>
		            <div class="modal-footer">
		            	<button type="button" id="saveBtn" class="btn btn-primary" onclick="">保存</button>
		            	<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		            </div>
		        </div><!-- /.modal-content -->
		    </div><!-- /.modal-dialog -->
		</div>
		<!-- /.modal --> 
	</div>
</div>	
</c:if>


<c:if test="${params=='choose' }">
<div class="panel panel-primary">
    <div class="panel-heading">属性值数据字典</div>
    <div class="panel-body"> 

		<form class="form-horizontal" id="defaultForm" action="ProductAttrDict_listByPage.action?params=choose" method="post">
		  	<table>
		  		<tr>
		  			<td><input type="text" name="t1.standardValue" class="form-control" id="standardValue" placeholder="请输入属性标准值名称" style="width: 150px"  value="${t1.standardValue}"></td>
		  			    <input type="hidden" name="t1.productAttr.id" value="${t1.productAttr.id}">
		  			<td><button type="submit" class="btn btn-default">查询</button></td>
		  		</tr>
		  	</table>
		</form>
 
    </div>
  
  
        <table class="table table-bordered table-hover">
            <thead>
			    <tr>
					 <th>标准值</th>
			         <th>操作</th>
			    </tr>
		    </thead>
		    <s:iterator value="#list">
			    <tr>
					<th>${standardValue }</th>
			        <th>
				        <input type="hidden" name="nameChoose" id="${id }" value="${standardValue }"/>
						<input type="radio" name="idChoose" value="${id }"/>
			        </th>
			    </tr>        
		    </s:iterator>
		</table>  
</div>
</c:if>
	
<section id="main-content">
    <p>
        <div class="text-center" display="inline">
            <ul id="pagination-demo" class="pagination-sm">&nbsp;&nbsp;&nbsp;共${pageCount}页</ul>
        </div>
    </p>
</section> 
	

</body>
</html>
